/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: AcademicProgram.java
 * Date: 17/11/2010
 */

package com.ingenius.sau.shared.model.programs;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.FetchGroup;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NullValue;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.ingenius.sau.shared.model.core.BaseBean;
import com.ingenius.sau.shared.model.core.SelfEvaluation;

/**
 * Class <strong>AcademicProgram</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@FetchGroup(name = "with_evaluations", members = { @Persistent(name = "evaluations") })
public class AcademicProgram implements BaseBean {

	// CONSTANTS

	public static final String NON_PRESENTIAL = "Non presential";

	public static final String PRESENTIAL = "Presential";

	// DATA

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;

	@Persistent(nullValue = NullValue.NONE)
	private String code;

	@Persistent(nullValue = NullValue.NONE)
	private String name;

	@Persistent(nullValue = NullValue.NONE)
	private String mission;

	@Persistent(nullValue = NullValue.NONE)
	private String vision;

	@Persistent(nullValue = NullValue.NONE)
	private String titleGranted;

	@Persistent(nullValue = NullValue.NONE)
	private String modality = PRESENTIAL;

	@Persistent(nullValue = NullValue.NONE)
	private Integer duration;

	@Persistent(mappedBy = "academicProgram")
	@Element(dependent = "true")
	private List<SelfEvaluation> evaluations;

	// CONSTRUCTORS

	public AcademicProgram() {
	}

	public AcademicProgram(String id) {
		this.id = id;
	}

	// METHODS

	public String getId() {
		return id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMission() {
		return mission;
	}

	public void setMission(String mission) {
		this.mission = mission;
	}

	public String getVision() {
		return vision;
	}

	public void setVision(String vision) {
		this.vision = vision;
	}

	public String getTitleGranted() {
		return titleGranted;
	}

	public void setTitleGranted(String titleGranted) {
		this.titleGranted = titleGranted;
	}

	public String getModality() {
		return modality;
	}

	public void setModality(String modality) {
		if (PRESENTIAL.equals(modality) || NON_PRESENTIAL.equals(modality)) {
			this.modality = modality;

		} else {
			System.out.println("Invalid argument exception. " + modality);
		}
	}

	public Integer getDuration() {
		return duration;
	}

	public void setDuration(int duration) {
		this.duration = duration;
	}

	public List<SelfEvaluation> getSelfEvaluations() {
		return (evaluations == null) ? new ArrayList<SelfEvaluation>()
				: evaluations;
	}

	public void setSelfEvaluations(List<SelfEvaluation> evaluations) {
		this.evaluations = evaluations;
	}

	public void addSelfEvaluation(SelfEvaluation evaluation) {
		getSelfEvaluations().add(evaluation);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof AcademicProgram) {
			return ((AcademicProgram) obj).getId().equals(id);
		}
		return false;
	}

	public AcademicProgram toDTO() {
		if (this != null) {
			this.setSelfEvaluations(null);
		}
		return this;
	}

}
